export const request = (url, method, params) => {
	const token = uni.getStorageSync('token')? uni.getStorageSync('token'):'';
	console.log(token)
	uni.showLoading({
		title: "加载中"
	});
	let data = {
		url: 'http://zwh.huijipin.cn/api/' + url,
		method: method,
		data: {
			...params,
		},
	}
	return new Promise((resolve, reject) => {
		uni.request({
			...data,
			header: {
				token:token
				// Authorization: '', //请求头
			},
			success(res) {
				const {
					code,
					msg
				} = res.data;
				switch (code) {
					case 401: //错误码token
						uni.showToast({
							title: '请登录',
							icon: "error",
						});
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/login/login'
							})
						}, 1000)
						break;
					default:
						resolve(res.data);
						uni.hideLoading();
						break;
				}
			},
			fail(err) {
				reject(err);
				uni.hideLoading();
			},
			complete() {
				uni.hideLoading();
			}
		});
	});
}
export const api = (url, params, qingqiu) => { //主性格
	let a = qingqiu ? qingqiu : 'post'
	return request(url, a, params)
}
